/*
Content: Regressions with PASS, Table G.9
Paper: "Immigrants Return Intentions and Labor Market Behavior when the Home Country is Unsafe"
Journal: Journal of Labor Economics
Authors: Jacopo Bassetto, Teresa Freitas-Monteiro
File version: 1.1 - May 8th, 2025
Stata version: 
*/



********************************************************************************
**# LOAD DATASET
********************************************************************************

"${data}/finaldata_terrorpass_light_final.dta", replace
	
					
********************************************************************************
**# Table G.9
********************************************************************************

**# Outcome creation

* Reservation wage and expected wage
cap drop reservation_wage
gen reservation_wage = PAS1800 if PAS1800 > 0 & PAS1800 != . 
replace reservation_wage = PAS2100 if PAS2000 == 1 & PAS2100 > 0 & PAS2100 != .
replace reservation_wage = PAS2200 if reservation_wage == . & PAS2200 > 0 & PAS2200 != .
*replace reservation_wage = PAS1800 if reservation_wage <0 | reservation_wage ==.
replace reservation_wage = . if reservation_wage < 0

gen min_wage = PAS2100 if PAS2100 > 0 & PAS2100 != .
gen exp_wage = PAS1800 if PAS1800 > 0 & PAS1800 != . 


cap drop ln_reswage
gen ln_reswage = log(reservation_wage)
gen ln_expwage = log(PAS1800) if PAS1800 > 0 & PAS1800 != .


* Hours worked
cap drop hours_work
gen hours_work = PAS1900 if PAS1900 >= 0 & PAS1900 != .
*replace hours_work = PAS2300 if hours_work == . & PAS2300 >=0 & PAS2300 !=.


recode PAS0400 (1 = 1) (2 = 0) (else =.), gen(jobsearch)

	
**# Regression


* WAGES AND HOURS WORKED

local varlist ln_expwage ln_reswage hours_work 

eststo clear
local i=1	
foreach out of varlist `varlist'	{	
foreach var in  m3y   {

global select_reg_M "!inlist(ogeblandna,.,1) & inrange(distanceterror_`var'_p90,-3,3) & distanceterror_`var'_p90!= 0 &  mratiointerterror_m3y_p90!=1"
global controls "i.ogeblandna#i.year i.month#i.year" 	

qui: reghdfe `out' postterror_`var'_p90 /* i.sex c.age c.ysm##c.ysm i.maritstat i.educ_aftm2 i.child*/ if $select_reg_M, vce(cluster clusterterror_`var'_p90) absorb($controls)
cap drop  sample_terror_`var'
qui:  g sample_terror_`var'=e(sample)


global select_reg_M "!inlist(ogeblandna,.,1) & inrange(distanceterror_`var'_p90,-3,3) & !inlist(distanceterror_`var'_p90,0)"
global controls "i.ogeblandna#i.year i.year#i.month" 	


reghdfe `out' postterror_`var'_p90 i.sex i.edu_3cat i.maritstat c.age c.ysm##c.ysm if $select_reg_M & sample_terror_`var' ==1 & ysm !=. & exp_wage != ., vce(cluster cluster3) absorb($controls)
eststo m`i'
local i=`i'+1
sum	 `out' if $select_reg_M & sample_terror_`var' ==1 & postterror_m3y_p90==0
estadd scalar ymean1 = r(mean)


}
}

* JOB SEARCH

local varlist jobsearch 

local i=1	
foreach out of varlist `varlist'	{	
foreach var in  m3y   {

global select_reg_M "!inlist(ogeblandna,.,1) & inrange(distanceterror_`var'_p90,-3,3) & distanceterror_`var'_p90!= 0 &  mratiointerterror_m3y_p90!=1"
global controls "i.ogeblandna#i.year i.month#i.year" 	

qui: reghdfe `out' postterror_`var'_p90 /* i.sex c.age c.ysm##c.ysm i.maritstat i.educ_aftm2 i.child*/ if $select_reg_M, vce(cluster clusterterror_`var'_p90) absorb($controls)
cap drop  sample_terror_`var'
qui:  g sample_terror_`var'=e(sample)


global select_reg_M "!inlist(ogeblandna,.,1) & inrange(distanceterror_`var'_p90,-3,3) & !inlist(distanceterror_`var'_p90,0,1)"
global controls "i.ogeblandna#i.year i.year#i.month" 	


reghdfe `out' postterror_`var'_p90 i.sex i.edu_3cat i.maritstat c.age c.ysm##c.ysm if $select_reg_M & sample_terror_`var' ==1 & ysm !=., vce(cluster cluster3) absorb($controls)
eststo m`i'_plus
local i=`i'+1
sum	 `out' if $select_reg_M & sample_terror_`var' ==1 & postterror_m3y_p90==0
estadd scalar ymean = r(mean)
estadd local yearorigin "Yes"
estadd local yearmonth "Yes"
estadd local state "Yes"
estadd local control "Yes"

}
}

esttab m*  using "$table/PASS_mechanisms_final.tex", star(* 0.10 ** 0.05 *** 0.01) se replace b(3) drop(_cons *maritstat *edu_3cat *sex *ysm *age) nocons  mtitles("\shortstack{Log monthly\\exp wage}" "\shortstack{Log monthly\\res wage}" "\shortstack{Preferred\\nr hours}" "\shortstack{Active in\\last 4 weeks}") varlabel(postterror_m3y_p90 "Post-Terror") ///
nocons nogaps nonotes noobs nomtitle ///
scalars("nobs Observations" "ymean Mean outcome" "yearorigin Origin country x Year FE" "yearmonth Month FE x Year FE" "state State of Residency FE" "control Individual Controls") ///
sfmt(%9.0fc %9.3f %1s %1s %1s %1s ) 






